import os
import datetime as dt

script_path = "manage.py"

print("time: ", dt.datetime.now().strftime("%Y/%m/%d %H:%M:%S"))
cmd_ps = 'ps -aux | grep "' + script_path + ' runserver 0:8000"'
pid = ""
lines = os.popen(cmd_ps)
for line in lines.readlines():
    if "python3 " + script_path in line:
        for sp in line.split(" "):
            if sp == "root" or sp == "":
                continue
            pid = sp
            break

if pid != "":
    print("found pid: ", pid)
    cmd_kill = "kill -9 " + pid
    os.system(cmd_kill)
    print("killed: " + pid)
else:
    print("pid not found")